package com.example.castday1.test;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.castday1.bean.UserA;
import com.example.castday1.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @Author : 徐闯 mpcast
 * @Date : 2021-05-23 20:05:36
 * @Description : 测试LambadaQueryWrapper 条件构造器
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class F_TestLambadaQUery {
    @Autowired
    private UserMapper userMapper;
    @Test
    public void testLambada(){
        // 获取LambdaQueryWrapper的方式
        // 方式1  直接new LambdaQueryWrapper的对象
        //LambdaQueryWrapper<UserA> lambdaQueryWrapper = new LambdaQueryWrapper();
        // 方式2 使用QueryWrapper 获取 LambadaQueryWrapper
        //LambdaQueryWrapper<UserA> lambdaQueryWrapper = new QueryWrapper().lambda();
        //方式3 通过Wrappers获取LambdaQueryWrapper
        LambdaQueryWrapper<UserA> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.like(UserA::getUsername,"zs");
        List<UserA> userAList = userMapper.selectList(lambdaQueryWrapper);
        userAList.forEach(System.out::println);
    }
}
